home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: redoFileRemoveSlotted.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:58 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "latch.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "log.h"
- #include "pool.h"
- #include "volume.h"
- #include "logrecs.h"
- #include "trans.h"
- #include "bitmap.h"
- #include "file.h"
- #include "openlog.h"
- #include "bf_extfuncs.h"
- #include "bm_extfuncs.h"
- #include "fi_intfuncs.h"
- #include "trans_extfuncs.h"
- #include "redo_extfuncs.h"
- #include "logaction.h"
- #include "util_funcs.h"
- #include "thread_globals.h"
- #include "bf_globals.h"
- #include "log_globals.h"
- #include "log_extfuncs.h"
-
-
- /*
- * This function redoes the setting of the file root page pointers
- * to the first and last logical pages in the file, and the
- * setting of the nextLogicalPid field of the last page in the
- * file
- */
-
- void
- redoFileRemoveSlotted (
-
- LOGRECORDHDR *record
- )
- {
-
- PID *rootPID;
- PID lastPID;
- NODEPAGE *nodePage;
- SLOTTEDPAGE *slottedPage;
- GROUPLINK *groupLink;
- BOOL firstPage;
- DIRTYPAGEINFO *dirtyInfo;
- LRC *lrc;
-
-
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_1, ("lsn:%d", record->recordLSN.offset));
- SM_ASSERT(LEVEL_3, record->type == LOG_REC_TYPE_COMPENSATION);
-
- /*
- * get a pointer to the file root page id
- * get flag for whether this is the first page in the file
- * get pid of new page added to file
- */
- rootPID = &(record->actionPid);
- firstPage = *(BOOL*) GET_LOG_IMAGE(record, 0);
- TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("file root page:%d", rootPID->page));
- if (!firstPage) {
-
- /*
- * Get a pointer to the last slotted page in the file
- * and a pointer to the log record lrc for this page
- */
- lastPID.page = *(SHORTPID*) GET_LOG_IMAGE(record, 1);
- lastPID.volid = rootPID->volid;
- lrc = (LRC*) GET_LOG_IMAGE(record, 2);
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("last slotted page:%d", lastPID.page));
- }
-
- /*
- * check to see if the root page is in the dirty page list
- */
- if ((dirtyInfo = searchDirtyPageTable(rootPID)) == NULL) {
-
- /*
- * don't need to redo
- */
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
- goto handle_page_link;
- }
-
- /*
- * check to see if the lrc on the page is greater than
- * the lrc in the log record.
- * Also check the lsn for the case of pages which never made it
- * back from the client.
- */
- if (CHECK_PAGE_LRC_LESS_DIRTYINFO(record->actionLRC, record->recordLSN, dirtyInfo)) {
-
- /*
- * don't need to redo
- */
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
- return;
- }
-
-
- /*
- * Read in first page of file and grab node type
- */
- if ((groupLink = bf_ReadPage(UserBufGroup, rootPID, FILE_PAGE2SIZE, BF_SEM)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * get a pointer to the node page
- */
- nodePage = (NODEPAGE *) groupLink->bufFrame;
-
- /*
- * check to see if the lrc on the page is greater than
- * the lrc in the log record
- */
- if (compareLRC( &(record->actionLRC), &(nodePage->header.lrc)) <= 0) {
-
- /*
- * don't need to redo
- * mark the page lrc
- */
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
- dirtyInfo->lrc = nodePage->header.lrc;
-
- /*
- * release the page
- */
- signalSemaphore( &(groupLink->pageHash->semaphore) );
- bf_UnfixPage(groupLink, BF_DEFAULT, FALSE);
- goto handle_page_link;
- }
-
- /*
- * See if this was the first page added and then update the
- * proper pointers
- */
- if (firstPage) {
-
- /*
- * Update the first and the last
- */
- SM_ASSERT(LEVEL_3, nodePage->header.firstLogicalNode != NULLPID && nodePage->header.lastLogicalNode != NULLPID);
- nodePage->header.firstLogicalNode = NULLPID;
- nodePage->header.lastLogicalNode = NULLPID;
-
- } else {
-
- /*
- * Update the only the last
- */
- nodePage->header.lastLogicalNode = lastPID.page;
- }
-
- /*
- * mark the LRC on the page
- * Set up the firstLSN/LRC for the page
- */
- nodePage->header.lrc = record->actionLRC;
- DEPEND_LOG(groupLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d", nodePage->header.lrc.count));
-
- /*
- * release the page semaphore
- */
- signalSemaphore( &(groupLink->pageHash->semaphore) );
-
- /*
- * release and dirty the page
- */
- bf_UnfixPage(groupLink, BF_DEFAULT, TRUE);
-
- /*
- * Update link on last page in the file
- */
- handle_page_link:
-
- /*
- * If this is not the first page, then update the link on the
- * last page
- */
- if (!firstPage) {
-
- /*
- * check to see if the last page is in the dirty page list
- */
- if ((dirtyInfo = searchDirtyPageTable(&lastPID)) == NULL) {
-
- /*
- * don't need to redo
- */
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
- return;
- }
-
- /*
- * check to see if the lrc on the page is greater than
- * the lrc in the log record
- */
- if (compareLRC( lrc, &(dirtyInfo->lrc) ) < 0) {
-
- /*
- * don't need to redo
- */
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
- return;
- }
-
- /*
- * Make sure the comparison was correct
- */
- SM_ASSERT(LEVEL_3, compareLSN( &(record->recordLSN), &(dirtyInfo->lsn)) >= 0);
-
- /*
- * Read in last page of file
- */
- if ((groupLink = bf_ReadPage(UserBufGroup, &lastPID, SLOTTED_PAGE2SIZE, BF_SEM)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * get a pointer to the node page
- */
- slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
-
- /*
- * check to see if the lrc on the page is greater than
- * the lrc in the log record. Note that the comparison is
- * < not <= since the lrc was not incremented upon the
- * generation of this log record.
- */
- if (compareLRC( lrc, &(slottedPage->header.lrc)) < 0) {
-
- /*
- * don't need to redo
- * mark the page lrc
- */
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
- dirtyInfo->lrc = nodePage->header.lrc;
-
- /*
- * release the page
- */
- signalSemaphore( &(groupLink->pageHash->semaphore) );
- bf_UnfixPage(groupLink, BF_DEFAULT, FALSE);
- return;
- }
-
- /*
- * Redo the link update
- */
- slottedPage->header.nextLogicalPid = NULLPID;
-
- /*
- * don't mark the LRC on the page
- * Set up the firstLSN/LRC for the page
- */
- /*slottedPage->header.lrc = *lrc;*/
- DEPEND_LOG(groupLink->pageHash, 0, &(record->recordLSN), lrc);
- TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d", slottedPage->header.lrc.count));
-
- /*
- * release the page semaphore
- */
- signalSemaphore( &(groupLink->pageHash->semaphore) );
-
- /*
- * release and dirty the page
- */
- bf_UnfixPage(groupLink, BF_DEFAULT, TRUE);
- }
- }
-